
import com.wcarmon.life.event.*;
import com.wcarmon.life.model.*;
import com.wcarmon.life.vo.*;
import mx.controls.Alert;
import mx.collections.*;
import mx.events.*;
import mx.managers.*;
import mx.utils.*;
      	
 		
include "../../../includes/loggerSnippet.as";
      	    
      	         
[Bindable]
private var model : LifeModelLocator = LifeModelLocator.getInstance();


////////////////////////////////////////////////////////
private var _initialProjectId : int;
public function get initialProjectId() : int {
	return initialProjectId;
}
public function set initialProjectId( p : int ) : void{
	var tmp:int = -1;
	if( p is uint ){ 
		tmp = p;	 
	}
	this._initialProjectId = tmp;
	BlockProjectIds.setInitialValue( tmp ); 
}
////////////////////////////////////////////////////////







private function doInit() : void {
	BlockContent.setFocus();
	
	log.debug( "Givon: _initialProjectId for minicollect = " + _initialProjectId );
	if( _initialProjectId is uint ){
		log.fatal('Givon implement setting initial project id for mini-collect');	
	}
}

private function saveToInbox(event : CloseEvent) : void {
	if( !isValid() ){
		return;
	}
	
	var b : BlockVO = new BlockVO();
	b.content = BlockContent.getValue();
	b.ref_meta = BlockRefMeta.getValue();
	b.deadline = BlockDeadline.getValue();
	b.projectIds = BlockProjectIds.getValue();
	  
	b.state_id = BlockVO.STATE_COLLECT;
	b.isPrivate = 1;
	
	log.debug('MiniCollect about to save this: \n' + ObjectUtil.toString(b) );

	///////////////////////////////////////////////
	( new CreateBlockEvent( b, this ) ).dispatch();
}

private function isValid() : Boolean {
	if( !BlockContent.isValid() ){ return false; }
	if( !BlockDeadline.isValid() ){ return false; }
	if( !BlockRefMeta.isValid() ){ return false; }
	if( !BlockProjectIds.isValid() ){ return false; }
	
	log.debug('mini-collect fields are all valid');
	return true;
}
	
public function doCallback() : void {
	closeDialog(null);
}
         
private function closeDialog(event : CloseEvent) : void {
	PopUpManager.removePopUp(this); // close this dialog 
}
